import { Entity, PrimaryGeneratedColumn, Column, Unique, ManyToOne, JoinColumn } from 'typeorm';
import { User } from './User';

@Entity()
@Unique(['userId', 'gname'])
@Unique(['userId', 'gid'])
export class DeviceGroup {
  @PrimaryGeneratedColumn('uuid')
  gid!: string;

  @Column()
  userId!: string;

  @Column()
  gname!: string;


  @ManyToOne(() => User, user => user.deviceGroups, {
    onDelete: 'CASCADE' // 删除用户时，级联删除分组
  })
  @JoinColumn({ name: 'userId' })
  user!: User;
}
